home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1996-08-08 | 61.4 KB | 2,443 lines | [ TEXT/CWIE]
// // GrayCouncilMA // Copyright ©1996 by Trygve Isaacson. All Rights Reserved. // // MacApp adapter classes for core Gray Council. // // Before using any of the GrayCouncil source code, read and // follow the licensing info in the accompanying documentation // or contact: // <trygve@kagi.com> // <http://www.kagi.com/authors/trygve/> // // GrayCouncil provides a set of standard C++ classes that implement // the standard Apple Grayscale Appearance. The core classes do not // require any other code such as a particular class framework. // // This file defines a set of helper classes that derive from standard // MacApp view classes, and interface with the core Gray Council code. // There are also a couple of adorner subclasses for attaching to windows // and list boxes to get the correct background color or target border. // // Normally, to use a GrayCouncil MacApp class, you can simply change the // class name of the subview in your resource file or AdLib view to the // class name of the appropriate Gray Council MacApp adapter class. For // example, to use the GC pushbutton, create a normal TButton subview, // and set its class name to AGAPushButtonMA. Voila. // // A couple of the classes use the userData field of the subview to specify // additional information such as icon IDs, string resource IDs, etc. // // Each class here that interfaces to a core AGAObject has a public // member variable called mAGAObject that points to the actual AGAObject // subclass object. Certain extended object settings (such as mixed-state // buttons, proportional and live scrolling, etc.) require you to call // the AGAObject to set it. The member variable is made public to keep // these MacApp classes as lightweight as possible; you make the call, // rather than using myriad new functions of the MacApp AGA subclasses. // // Classes defined below: // AGAPushButtonMA -- TButton subclass for AGAPushButton // AGACheckBoxMA -- TCheckBox subclass for AGACheckBox // AGARadioButtonMA -- TRadio subclass for AGARadioButton // AGAIconPushButtonMA -- AGAPushButtonMA (TButton) subclass for AGAIconPushButton // AGAIconCheckBoxMA -- AGACheckBoxMA (TCheckBox) subclass for AGAIconCheckBox // AGAIconRadioButtonMA -- AGARadioButtonMA (TRadio) subclass for AGAIconRadioButton // AGAScrollBarMA -- TScrollBar subclass for AGAScrollBar // AGAScrollerScrollBarMA -- TScrollerScrollBar subclass for AGAScrollBar // Remember the difference between TScrollBar and TScrollerScrollBar! // AGASliderMA -- TControl subclass for AGASlider // AGABackgroundAdornerMA -- TAdorner subclass that you should attach to // typical modeless windows; gives it the proper modeless gray background // AGAModalBackgroundAdornerMA -- AGABackgroundAdornerMA (TAdorner) subclass // that you should attach to modal windows (i.e., things you PoseModally); // gives it the proper modal gray background // AGAWhiteBackgroundAdornerMA -- TAdorner subclass you should attach to any // view that needs a white background but lives in a gray background window // (e.g., TEditText, TScroller containing grid, etc.) // AGABorderFrameAdornerMA -- TAdorner subclass that you can attach to any // view that needs a "3D" sunken frame around it (e.g., the same things // that need a white background adorner) // AGAPopupMA -- TPopup subclass for AGAPopupMenu // AGAStaticTextMA -- TStaticText subclass for AGAStaticText // AGALittleArrowsMA -- TControl subclass for AGALittleArrows // AGADisclosureTriangleMA -- TControl subclass for AGADisclosureTriangle // AGAProgressIndicatorMA -- TControl subclass for AGAProgressIndicator // AGASeparatorMA -- TView subclass for AGASeparator // AGATargetBorderViewMA -- TTargetBorderView subclass that draws AGA-style // target border frame // AGAClusterMA -- TCluster subclass for AGAGroupBox // AGASecondaryClusterMA -- AGAClusterMA (TCluster) subclass for AGAGroupBox // with secondary box style set // #include "GrayCouncilMA.h" #include <plstringfuncs.h> OSErr InitGrayCouncilMA() { // // Register our dynamically instantiated view subclasses. // MA_REGISTER_CLASS(AGAPushButtonMA); MA_REGISTER_CLASS(AGACheckBoxMA); MA_REGISTER_CLASS(AGARadioButtonMA); MA_REGISTER_CLASS(AGAIconPushButtonMA); MA_REGISTER_CLASS(AGAIconCheckBoxMA); MA_REGISTER_CLASS(AGAIconRadioButtonMA); MA_REGISTER_CLASS(AGAScrollBarMA); MA_REGISTER_CLASS(AGAScrollerScrollBarMA); MA_REGISTER_CLASS(AGASliderMA); MA_REGISTER_CLASS(AGABackgroundAdornerMA); MA_REGISTER_CLASS(AGAModalBackgroundAdornerMA); MA_REGISTER_CLASS(AGAPopupMA); MA_REGISTER_CLASS(AGAStaticTextMA); MA_REGISTER_CLASS(AGALittleArrowsMA); MA_REGISTER_CLASS(AGAWhiteBackgroundAdornerMA); MA_REGISTER_CLASS(AGABorderFrameAdornerMA); MA_REGISTER_CLASS(AGADisclosureTriangleMA); MA_REGISTER_CLASS(AGAProgressIndicatorMA); MA_REGISTER_CLASS(AGASeparatorMA); MA_REGISTER_CLASS(AGATargetBorderViewMA); MA_REGISTER_CLASS(AGATargetBorderFrameViewMA); MA_REGISTER_CLASS(AGAGroupBoxMA); MA_REGISTER_CLASS(AGASecondaryGroupBoxMA); // Do Core Gray Council initialization. return InitGrayCouncil(); } static void SetAGAObjectFrame(TView* itsView, AGAObject* theAGAObject, const VRect& newViewFrame, Boolean redraw) { if (theAGAObject != NULL) { VRect viewRect(0, 0, itsView->fSize.h, itsView->fSize.v); CRect qdRect; itsView->ViewToQDRect(viewRect, qdRect); theAGAObject->SetObjectBounds(qdRect, AGAObject::kDontRedraw); } } // // AGAPushButtonMA ---------------------------------------------------- // #undef Inherited #define Inherited TButton MA_DEFINE_CLASS_M1(AGAPushButtonMA, Inherited); AGAPushButtonMA::AGAPushButtonMA() { mAGAObject = NULL; } AGAPushButtonMA::~AGAPushButtonMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGAPushButtonMA::IAGAPushButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel) { this->IButton(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel); this->CreateAGAObject(); } void AGAPushButtonMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGAPushButtonMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; CStr255 viewTitle; this->ViewToQDRect(viewRect, bounds); this->GetText(viewTitle); FailNIL(mAGAObject = new AGAPushButton(bounds, AGATextStyle(fTextStyle), viewTitle)); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); // // We implement the default button outline by checking for the // presence of the TRRectAdorner by std ID, tossing it, and // telling the AGA button object that it is a default button. // TAdorner* rrectAdorner = this->FindRRectAdorner(); if (rrectAdorner) { this->DeleteAdorner(rrectAdorner, kDontInvalidate); mAGAObject->SetDefault(AGAObject::kIsDefault, AGAObject::kFrameInside); } } void AGAPushButtonMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGAPushButtonMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGAPushButtonMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse; if tracking succeeds // handle our event number. if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse))) this->HandleEvent(fEventNumber, this, NULL); } void AGAPushButtonMA::HiliteState(Boolean state, Boolean redraw) { // Let the AGAPushButton draw in the specified state. if ((mAGAObject != NULL) && this->Focus()) mAGAObject->DrawButton(state); } void AGAPushButtonMA::Hilite() { // Let the AGAPushButton draw in pressed state. if ((mAGAObject != NULL) && this->Focus()) mAGAObject->DrawButton(AGAObject::kPressed); } void AGAPushButtonMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if ((mAGAObject != NULL) && this->Focus()) mAGAObject->SetEnable(!state, redraw); } void AGAPushButtonMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } TAdorner* AGAPushButtonMA::FindRRectAdorner() { // Return the TRRectAdorner, if any, that is attached to // this push button. TAdorner* foundAdorner = NULL; if (fAdorners != NULL) { CAdornerIterator iter(this); for (TAdorner* theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner()) { if (MA_MEMBER(theAdorner, TRRectAdorner)) foundAdorner = theAdorner; } } return foundAdorner; } // // AGACheckBoxMA ---------------------------------------------------- // #undef Inherited #define Inherited TCheckBox MA_DEFINE_CLASS_M1(AGACheckBoxMA, Inherited); AGACheckBoxMA::AGACheckBoxMA() { mAGAObject = NULL; } AGACheckBoxMA::~AGACheckBoxMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGACheckBoxMA::IAGACheckBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn) { this->ICheckBox(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn); this->CreateAGAObject(); } void AGACheckBoxMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGACheckBoxMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; CStr255 viewTitle; this->ViewToQDRect(viewRect, bounds); this->GetText(viewTitle); FailNIL(mAGAObject = new AGACheckBox(bounds, AGATextStyle(fTextStyle), viewTitle, AGAObject::kNoAutomaticState)); if (this->GetLongVal() != 0) mAGAObject->SetValue(AGACheckBox::kCheckBoxOn, AGAObject::kDontRedraw); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGACheckBoxMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGACheckBoxMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGACheckBoxMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse; if tracking succeeds // handle our event number. if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse))) this->HandleEvent(fEventNumber, this, NULL); } void AGACheckBoxMA::HiliteState(Boolean state, Boolean redraw) { // Let the AGACheckBox draw in the specified state. if ((mAGAObject != NULL) && this->Focus()) mAGAObject->DrawButton(state); } void AGACheckBoxMA::Hilite() { // Let the AGACheckBox draw in pressed state. if ((mAGAObject != NULL) && this->Focus()) mAGAObject->DrawButton(AGAObject::kPressed); } void AGACheckBoxMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGACheckBoxMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } Boolean AGACheckBoxMA::IsOn() { // Return true if it's on. if (mAGAObject == NULL) return Inherited::IsOn(); else return mAGAObject->GetValue() == AGACheckBox::kCheckBoxOn; } void AGACheckBoxMA::SetState(Boolean state, Boolean redraw) { // Set the state to on or off. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetValue(state, wantRedraw); } } void AGACheckBoxMA::Toggle(Boolean redraw) { // Toggle the state between on and off. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); this->SetState(! this->IsOn(), wantRedraw); } } void AGACheckBoxMA::ToggleIf(Boolean matchState, Boolean redraw) { // Toggle the state if it's currently in the specified state. if (mAGAObject != NULL) if (this->IsOn() == matchState) { Boolean wantRedraw = redraw && this->Focus(); this->SetState(! this->IsOn(), wantRedraw); } } // // AGARadioButtonMA ---------------------------------------------------- // #undef Inherited #define Inherited TRadio MA_DEFINE_CLASS_M1(AGARadioButtonMA, Inherited); AGARadioButtonMA::AGARadioButtonMA() { mAGAObject = NULL; } AGARadioButtonMA::~AGARadioButtonMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGARadioButtonMA::IAGARadioButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn) { this->IRadio(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn); this->CreateAGAObject(); } void AGARadioButtonMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGARadioButtonMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; CStr255 viewTitle; this->ViewToQDRect(viewRect, bounds); this->GetText(viewTitle); FailNIL(mAGAObject = new AGARadioButton(bounds, AGATextStyle(fTextStyle), viewTitle, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState)); if (this->GetLongVal() != 0) mAGAObject->SetValue(AGARadioButton::kRadioButtonOn, AGAObject::kDontRedraw); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGARadioButtonMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGARadioButtonMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGARadioButtonMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse; if tracking succeeds // handle our event number. if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse))) this->HandleEvent(fEventNumber, this, NULL); } void AGARadioButtonMA::HiliteState(Boolean state, Boolean redraw) { // Let the AGARadioButton draw in the specified state. if ((mAGAObject != NULL) && this->Focus()) mAGAObject->DrawButton(state); } void AGARadioButtonMA::Hilite() { // Let the AGARadioButton draw in pressed state. if ((mAGAObject != NULL) && this->Focus()) mAGAObject->DrawButton(AGAObject::kPressed); } void AGARadioButtonMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGARadioButtonMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } Boolean AGARadioButtonMA::IsOn() { // Return true if it's on. if (mAGAObject == NULL) return Inherited::IsOn(); else return mAGAObject->GetValue() == AGARadioButton::kRadioButtonOn; } void AGARadioButtonMA::SetState(Boolean state, Boolean redraw) { // Set the state to on or off. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetValue(state, wantRedraw); } } void AGARadioButtonMA::Toggle(Boolean redraw) { // Toggle the state between on and off. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); this->SetState(! this->IsOn(), wantRedraw); } } void AGARadioButtonMA::ToggleIf(Boolean matchState, Boolean redraw) { // Toggle the state if it's currently in the specified state. if (mAGAObject != NULL) if (this->IsOn() == matchState) { Boolean wantRedraw = redraw && this->Focus(); this->SetState(! this->IsOn(), wantRedraw); } } // // This function is used by all 3 icon button classes to get the icon type. // static UInt32 GetIconType(SInt16 width) { if (width > 39) return MIconButtonObject::kLargeIcon; else if (width > 21) return MIconButtonObject::kSmallIcon; else return MIconButtonObject::kMiniIcon; } // // AGAIconPushButtonMA ---------------------------------------------------- // #undef Inherited #define Inherited AGAPushButtonMA MA_DEFINE_CLASS_M1(AGAIconPushButtonMA, Inherited); void AGAIconPushButtonMA::IAGAIconPushButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel) { this->IAGAPushButtonMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel); } void AGAIconPushButtonMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); ResNumber iconID = fUserArea; UInt32 iconType = GetIconType(bounds.GetLength(hSel)); // static fn above FailNIL(mAGAObject = new AGAIconPushButton(bounds, iconID, iconType)); } // // AGAIconCheckBoxMA ---------------------------------------------------- // #undef Inherited #define Inherited AGACheckBoxMA MA_DEFINE_CLASS_M1(AGAIconCheckBoxMA, Inherited); void AGAIconCheckBoxMA::IAGAIconCheckBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn) { this->IAGAIconCheckBoxMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn); } void AGAIconCheckBoxMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); ResNumber iconID = fUserArea; UInt32 iconType = GetIconType(bounds.GetLength(hSel)); // static fn above FailNIL(mAGAObject = new AGAIconCheckBox(bounds, AGAObject::kNoAutomaticState, iconID, iconID, iconType)); if (this->GetLongVal() != 0) mAGAObject->SetValue(AGACheckBox::kCheckBoxOn, AGAObject::kDontRedraw); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } // // AGAIconRadioButtonMA ---------------------------------------------------- // #undef Inherited #define Inherited AGARadioButtonMA MA_DEFINE_CLASS_M1(AGAIconRadioButtonMA, Inherited); void AGAIconRadioButtonMA::IAGAIconRadioButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn) { this->IAGARadioButtonMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn); } void AGAIconRadioButtonMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); ResNumber iconID = fUserArea; UInt32 iconType = GetIconType(bounds.GetLength(hSel)); // static fn above FailNIL(mAGAObject = new AGAIconRadioButton(bounds, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState, iconID, iconID, iconType)); if (this->GetLongVal() != 0) mAGAObject->SetValue(AGARadioButton::kRadioButtonOn, AGAObject::kDontRedraw); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } // // AGAScrollBarMA ---------------------------------------------------- // #undef Inherited #define Inherited TScrollBar MA_DEFINE_CLASS_M1(AGAScrollBarMA, Inherited); AGAScrollBarMA::AGAScrollBarMA() { mNotificationRoutine = NULL; mAGAObject = NULL; } AGAScrollBarMA::~AGAScrollBarMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGAScrollBarMA::IAGAScrollBarMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsVal, long itsMin, long itsMax) { this->IScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, itsVal, itsMin, itsMax); this->CreateAGAObject(); } void AGAScrollBarMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData) { // Save the notification routine fn pointer and user data // for notification handling. mNotificationRoutine = notificationRoutine; mUserData = userData; } void AGAScrollBarMA::HandleNotification(SInt32 dataValue) { // Update the scrollbar value, call the installed notification // function, and propagate our event number. this->SetLongVal(dataValue, kDontRedraw); if (mNotificationRoutine != NULL) (*mNotificationRoutine)(this, dataValue, mUserData); this->HandleEvent(fEventNumber, this, NULL); (void) this->Focus(); // HandleEvent may have caused another view to draw } void AGAScrollBarMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGAScrollBarMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); FailNIL(mAGAObject = new AGAScrollBar(bounds, this->GetLongMin(), this->GetLongMax(), this->GetLongVal())); mAGAObject->InstallNotificationRoutine(AGAScrollBarMA::RealAGANotifier, this); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGAScrollBarMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGAScrollBarMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGAScrollBarMA::SetLongVal(VCoordinate itsVal, Boolean redraw) { // Catch all value changes here and synchronize the // AGAScrollBar accordingly. Inherited::SetLongVal(itsVal, redraw); if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetValue(itsVal, wantRedraw); } } void AGAScrollBarMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse. Don't call HandleEvent; // it has already been handled through HandleNotification. (void) mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)); } void AGAScrollBarMA::HiliteState(Boolean state, Boolean redraw) { // Suppress Control Manager scroll bar drawing. } void AGAScrollBarMA::Hilite() { // Suppress Control Manager scroll bar drawing. } void AGAScrollBarMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGAScrollBarMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } void AGAScrollBarMA::Activate(Boolean entering) { // Set the AGAScrollBar's activated state. if (mAGAObject != NULL) mAGAObject->Activate(entering, this->Focus()); } void AGAScrollBarMA::SetLongMax(VCoordinate itsMax, Boolean redraw) { // Set the AGAScrollBar's limit. Inherited::SetLongMax(itsMax, kDontRedraw); if (mAGAObject != NULL) { SInt32 itsMin; SInt32 itsMax; Boolean wantRedraw = redraw && this->Focus(); mAGAObject->GetRange(&itsMin, &itsMax); mAGAObject->SetRange(itsMin, this->GetLongMax(), wantRedraw); } } void AGAScrollBarMA::RealAGANotifier(AGATrackingIndicator* theIndicator, SInt32 dataValue, void* userData) { // This is a static function. Cast the user data to get // the AGAScrollBarMA object, have it handle the notification. ((AGAScrollBarMA*) userData)->HandleNotification(dataValue); } // // AGAScrollerScrollBarMA ---------------------------------------------------- // #undef Inherited #define Inherited TScrollerScrollBar MA_DEFINE_CLASS_M1(AGAScrollerScrollBarMA, Inherited); AGAScrollerScrollBarMA::AGAScrollerScrollBarMA() { mNotificationRoutine = NULL; mAGAObject = NULL; } AGAScrollerScrollBarMA::~AGAScrollerScrollBarMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGAScrollerScrollBarMA::IAGAScrollerScrollBarMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsMax, TScroller* itsScroller) { this->IScrollerScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, itsMax, itsScroller); this->CreateAGAObject(); } void AGAScrollerScrollBarMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData) { // Save the notification routine fn pointer and user data // for notification handling. mNotificationRoutine = notificationRoutine; mUserData = userData; } void AGAScrollerScrollBarMA::HandleNotification(SInt32 dataValue) { // Scroll our scrollers and call the installed notification // function. CObjectIterator iter(fScrollers); for (TScroller* aScroller = (TScroller*) iter.FirstObject(); iter.More(); aScroller = (TScroller*) iter.NextObject()) (void) aScroller->ScrollRelative(fDirection, dataValue); if (mNotificationRoutine != NULL) (*mNotificationRoutine)(this, dataValue, mUserData); (void) this->Focus(); } void AGAScrollerScrollBarMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGAScrollerScrollBarMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); FailNIL(mAGAObject = new AGAScrollBar(bounds, this->GetLongMin(), this->GetLongMax(), this->GetLongVal())); mAGAObject->InstallNotificationRoutine(AGAScrollerScrollBarMA::RealAGANotifier, this); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); this->UpdateScrollAmounts(); } void AGAScrollerScrollBarMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGAScrollerScrollBarMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp stuff relocate and recalculate, // then resynchronize the AGAScrollBar to the scrollers. Inherited::SetFrame(newFrame, invalidate); this->UpdateScrollAmounts(); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGAScrollerScrollBarMA::AttachScroller(TScroller* itsScroller) { // Synchronize the AGAScrollBar to the supplied scroller. Inherited::AttachScroller(itsScroller); this->UpdateScrollAmounts(); } void AGAScrollerScrollBarMA::SetLongVal(VCoordinate itsVal, Boolean redraw) { // Catch all value changes here and synchronize the // AGAScrollBar accordingly. Inherited::SetLongVal(itsVal, redraw); if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetValue(itsVal, wantRedraw); } } void AGAScrollerScrollBarMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse. Don't call HandleEvent; // it has already been handled through HandleNotification. (void) mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)); } void AGAScrollerScrollBarMA::HiliteState(Boolean state, Boolean redraw) { // Suppress Control Manager scroll bar drawing. } void AGAScrollerScrollBarMA::Hilite() { // Suppress Control Manager scroll bar drawing. } void AGAScrollerScrollBarMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGAScrollerScrollBarMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } void AGAScrollerScrollBarMA::Activate(Boolean entering) { // Set the AGAScrollBar's activated state. if (mAGAObject != NULL) mAGAObject->Activate(entering, this->Focus()); } void AGAScrollerScrollBarMA::SetLongMax(VCoordinate itsMax, Boolean redraw) { // Set the AGAScrollBar's limit. Inherited::SetLongMax(itsMax, kDontRedraw); if (mAGAObject != NULL) { SInt32 itsMin; SInt32 itsMax; Boolean wantRedraw = redraw && this->Focus(); mAGAObject->GetRange(&itsMin, &itsMax); mAGAObject->SetRange(itsMin, this->GetLongMax(), wantRedraw); } } void AGAScrollerScrollBarMA::UpdateScrollAmounts() { // Synchronize the AGAScrollBar to reflect the scroller // state. if ((mAGAObject != NULL) && (fScrollers->GetSize() > 0)) { TScroller* aScroller = (TScroller*) fScrollers->At(1); VCoordinate maxTranslation = aScroller->fMaxTranslation[fDirection]; VCoordinate viewSize = aScroller->fSize[fDirection]; VCoordinate singleStepSize = aScroller->fScrollUnit[fDirection]; VCoordinate pageStepSize = Max(0, viewSize - singleStepSize); VCoordinate pageSize = maxTranslation * (((float) (Max(0, viewSize - singleStepSize))) / ((float) (viewSize + maxTranslation))); (void) this->Focus(); mAGAObject->SetRange(0, maxTranslation, kDontRedraw); mAGAObject->SetPageSize(pageSize, kRedraw); mAGAObject->SetStepSizes(singleStepSize, pageStepSize); } } void AGAScrollerScrollBarMA::RealAGANotifier(AGATrackingIndicator* theIndicator, SInt32 dataValue, void* userData) { // This is a static function. Cast the user data to get // the AGAScrollerScrollBarMA object, have it handle the notification. ((AGAScrollerScrollBarMA*) userData)->HandleNotification(dataValue); } // // AGASliderMA ---------------------------------------------------- // #undef Inherited #define Inherited TControl MA_DEFINE_CLASS_M1(AGASliderMA, Inherited); AGASliderMA::AGASliderMA() { mAGAObject = NULL; } AGASliderMA::~AGASliderMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGASliderMA::IAGASliderMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle) { this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle); this->CreateAGAObject(); } void AGASliderMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGASliderMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); FailNIL(mAGAObject = new AGASlider(bounds, 0, 1, 0, AGATextStyle(fTextStyle), fUserArea)); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGASliderMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGASliderMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGASliderMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse; if tracking succeeds // handle our event number. if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse))) this->HandleEvent(fEventNumber, this, NULL); } void AGASliderMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGASliderMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } // // AGABackgroundAdornerMA ---------------------------------------------------- // #undef Inherited #define Inherited TAdorner MA_DEFINE_CLASS_M1(AGABackgroundAdornerMA, Inherited); AGABackgroundAdornerMA::AGABackgroundAdornerMA() { // Construct with color indexes for modeless gray background. // The edge values are slightly different when the window is // inactive. mRampIndexes[kBGFill] = r2; mRampIndexes[kBGActiveLight] = rW; mRampIndexes[kBGActiveShadow] = r5; mRampIndexes[kBGInactiveLight] = r1; mRampIndexes[kBGInactiveShadow] = r4; } void AGABackgroundAdornerMA::DoHighlightSelection(TView* itsView, const VRect& area, HLState fromHL, HLState toHL) { // Draw in the specified active/inactive state. this->DrawBackground(itsView, area, FALSE, (toHL == hlOn)); } void AGABackgroundAdornerMA::Draw(TView* itsView, const VRect& area) { // Draw in active state. this->DrawBackground(itsView, area, TRUE, itsView->IsActive()); } void AGABackgroundAdornerMA::ViewChangedFrame(TView* itsView, const VRect& oldFrame, const VRect& newFrame, Boolean invalidate) { // Make sure we invalidate the edges that will need to be // redrawn with the background edge pixel color. // Note that oldFrame & newFrame are in global coordinates. VRect rectToInvalidate; VPoint sizeDelta(newFrame.GetLength(hSel) - oldFrame.GetLength(hSel), newFrame.GetLength(vSel) - oldFrame.GetLength(vSel)); if (sizeDelta.h != 0) { if (sizeDelta.h > 0) rectToInvalidate = oldFrame; else // sizeDelta.h < 0 rectToInvalidate = newFrame; rectToInvalidate.left = rectToInvalidate.right - 1; itsView->SuperToLocalVRect(rectToInvalidate); itsView->InvalidateVRect(rectToInvalidate); } if (sizeDelta.v != 0) { if (sizeDelta.v > 0) rectToInvalidate = oldFrame; else // sizeDelta.v < 0 rectToInvalidate = newFrame; rectToInvalidate.top = rectToInvalidate.bottom - 1; itsView->SuperToLocalVRect(rectToInvalidate); itsView->InvalidateVRect(rectToInvalidate); } if (this->HasGrowBox(itsView)) { rectToInvalidate = oldFrame; rectToInvalidate.left = rectToInvalidate.right - 16; rectToInvalidate.top = rectToInvalidate.bottom - 16; itsView->SuperToLocalVRect(rectToInvalidate); itsView->InvalidateVRect(rectToInvalidate); rectToInvalidate = newFrame; rectToInvalidate.left = rectToInvalidate.right - 16; rectToInvalidate.top = rectToInvalidate.bottom - 16; itsView->SuperToLocalVRect(rectToInvalidate); itsView->InvalidateVRect(rectToInvalidate); } } void AGABackgroundAdornerMA::DrawBackground(TView* itsView, const VRect& area, Boolean fill, Boolean active) { CRect qdArea; itsView->GetQDExtent(qdArea); AGABackgroundPaint(qdArea, fill, kIsNotModal, active, this->HasGrowBox(itsView)); } Boolean AGABackgroundAdornerMA::HasGrowBox(TView* itsView) { if (MA_MEMBER(itsView, TWindow)) return ((TWindow*) itsView)->fIsResizable; else return FALSE; } // // AGAModalBackgroundAdornerMA ---------------------------------------------------- // #undef Inherited #define Inherited AGABackgroundAdornerMA MA_DEFINE_CLASS_M1(AGAModalBackgroundAdornerMA, Inherited); AGAModalBackgroundAdornerMA::AGAModalBackgroundAdornerMA() { // Construct with color indexes for modal gray background. mRampIndexes[kBGFill] = r2; mRampIndexes[kBGActiveLight] = rW; mRampIndexes[kBGActiveShadow] = r6; mRampIndexes[kBGInactiveLight] = r1; mRampIndexes[kBGInactiveShadow] = r4; } void AGAModalBackgroundAdornerMA::DrawBackground(TView* itsView, const VRect& area, Boolean fill, Boolean active) { CRect qdArea; itsView->GetQDExtent(qdArea); AGABackgroundPaint(qdArea, fill, kIsModal, active, this->HasGrowBox(itsView)); } // // AGAWhiteBackgroundAdornerMA ---------------------------------------------------- // #undef Inherited #define Inherited TAdorner MA_DEFINE_CLASS_M1(AGAWhiteBackgroundAdornerMA, Inherited); void AGAWhiteBackgroundAdornerMA::Draw(TView* itsView, const VRect& area) { // Draw the background in white, inset to avoid the border // frame pixels. CRect qdArea; itsView->GetQDExtent(qdArea); ::RGBForeColor(&gAGARamp[rW]); ::InsetRect(qdArea, 2, 2); ::PaintRect(qdArea); ::RGBForeColor(&gAGARamp[rB]); } // // AGABorderFrameAdornerMA ---------------------------------------------------- // #undef Inherited #define Inherited TAdorner MA_DEFINE_CLASS_M1(AGABorderFrameAdornerMA, Inherited); void AGABorderFrameAdornerMA::Draw(TView* itsView, const VRect& area) { // Draw the frame with shading outside. enum { TL, Frame, BR, kNumColors }; UInt8 colorIndex[kNumColors]; CRect qdArea; itsView->GetQDExtent(qdArea); GDIterator iter; Boolean deep; while (iter.More(deep)) { if (deep) { if (itsView->IsEnabled()) { colorIndex[TL] = r5; colorIndex[Frame] = rB; colorIndex[BR] = rW; } else { colorIndex[TL] = r4; colorIndex[Frame] = r10; colorIndex[BR] = r1; } } else // 1-bit { colorIndex[Frame] = rB; if (! itsView->IsEnabled()) ::PenPat(&qd.gray); } ::RGBForeColor(&gAGARamp[colorIndex[Frame]]); ::InsetRect(qdArea, 1, 1); ::FrameRect(qdArea); ::InsetRect(qdArea, -1, -1); if (deep) { ::RGBForeColor(&gAGARamp[colorIndex[TL]]); ::MoveTo(qdArea.left, qdArea.bottom - 2); ::LineTo(qdArea.left, qdArea.top); ::LineTo(qdArea.right - 2, qdArea.top); ::RGBForeColor(&gAGARamp[colorIndex[BR]]); ::MoveTo(qdArea.left + 1, qdArea.bottom - 1); ::LineTo(qdArea.right - 1, qdArea.bottom - 1); ::LineTo(qdArea.right - 1, qdArea.top + 1); } else if (! itsView->IsEnabled()) ::PenPat(&qd.black); } ::RGBForeColor(&gAGARamp[rB]); } // // AGAPopupMA ---------------------------------------------------- // #undef Inherited #define Inherited TPopup MA_DEFINE_CLASS_M1(AGAPopupMA, Inherited); AGAPopupMA::AGAPopupMA() { mAGAObject = NULL; } AGAPopupMA::~AGAPopupMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGAPopupMA::IAGAPopupMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, short itsMenuID, short itsCurrentItem, short itsItemOffset, short itsStrListID, short itsIndex, short itsStyle, short itsJust, Boolean useAddResMenu, ResType useAddResMenuResType, const TextStyle& itsTextStyle) { this->IPopup(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsMenuID, itsCurrentItem, itsItemOffset, itsStrListID, itsIndex, itsStyle, itsJust, useAddResMenu, useAddResMenuResType, itsTextStyle); this->CreateAGAObject(); } void AGAPopupMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGAPopupMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. (void) this->SetCMgrVisibility(FALSE); AGAPopupMenu::WidthAdjust widthAdjust; VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; CStr255 viewTitle; this->ViewToQDRect(viewRect, bounds); this->GetText(viewTitle); if (fSizeDeterminer[hSel] == sizeFixed) widthAdjust = AGAPopupMenu::kFixedWidth; else widthAdjust = AGAPopupMenu::kSystemMDEFAdjustment; FailNIL(mAGAObject = new AGAPopupMenu(bounds, fItemOffset, viewTitle, fTitleJust, AGATextStyle(fTextStyle), widthAdjust, this->GetMenuRef(), AGAPopupMenu::kDontDispose)); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGAPopupMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGAPopupMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGAPopupMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse; if tracking succeeds // handle our event number. if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse))) this->HandleEvent(fEventNumber, this, NULL); } void AGAPopupMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGAPopupMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } void AGAPopupMA::AttachMenuRef(MenuRef itsMenuRef) { // // Since TPopup owns the menu, it will do the disposal. // Inherited::AttachMenuRef(itsMenuRef); if (mAGAObject != NULL) mAGAObject->SetMenuRef(itsMenuRef, AGAPopupMenu::kDontDispose); } void AGAPopupMA::SetText(const CStr255& title, Boolean redraw) { Inherited::SetText(title, redraw); } void AGAPopupMA::SetLongVal(VCoordinate itsVal, Boolean redraw) { // Catch all value changes here and synchronize the // AGAPopupMenu accordingly. if (mAGAObject != NULL) mAGAObject->SetCurrentItemNo((SInt16) itsVal, redraw); else Inherited::SetLongVal(itsVal, redraw); } SInt16 AGAPopupMA::GetVal() { // Return the currently selected item number. if (mAGAObject != NULL) return mAGAObject->GetCurrentItemNo(); else return Inherited::GetVal(); } // // AGAStaticTextMA ---------------------------------------------------- // #undef Inherited #define Inherited TStaticText MA_DEFINE_CLASS_M1(AGAStaticTextMA, Inherited); AGAStaticTextMA::AGAStaticTextMA() { mAGAObject = NULL; } AGAStaticTextMA::~AGAStaticTextMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGAStaticTextMA::IAGAStaticTextMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex) { this->IStaticText(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex); this->CreateAGAObject(); } void AGAStaticTextMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); VRect viewRect(0, 0, fSize.h, fSize.v); CRect qdRect; this->ViewToQDRect(viewRect, qdRect); this->CreateAGAObject(); } void AGAStaticTextMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; CStr255 viewTitle; this->ViewToQDRect(viewRect, bounds); this->GetText(viewTitle); FailNIL(mAGAObject = new AGAStaticText(bounds, AGATextStyle(fTextStyle), fJust, viewTitle)); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGAStaticTextMA::SetText(const CStr255& theText, Boolean redraw) { // Change the current text in TStaticText and in // the AGAStaticText. Do NOT let TStaticText redraw, // because it erases to white. Inherited::SetText(theText, kDontRedraw); if (mAGAObject != NULL) { Str255 textString; Boolean wantRedraw = redraw && this->Focus(); PLstrcpy(textString, theText); mAGAObject->SetTitle(textString, wantRedraw); } } void AGAStaticTextMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGAStaticTextMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } void AGAStaticTextMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGAStaticTextMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } // // AGALittleArrowsMA ---------------------------------------------------- // #undef Inherited #define Inherited TControl MA_DEFINE_CLASS_M1(AGALittleArrowsMA, Inherited); AGALittleArrowsMA::AGALittleArrowsMA() { mNotificationRoutine = NULL; mAGAObject = NULL; mLinkedNumberText = NULL; } AGALittleArrowsMA::~AGALittleArrowsMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGALittleArrowsMA::IAGALittleArrowsMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle) { this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle); this->CreateAGAObject(); } void AGALittleArrowsMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData) { // Save the notification routine fn pointer and user data // for notification handling. mNotificationRoutine = notificationRoutine; mUserData = userData; } void AGALittleArrowsMA::HandleNotification(SInt32 deltaValue) { // Update the linked TNumberText, if any, call the // installed notification function, and propagate our // event number. if (mLinkedNumberText != NULL) mLinkedNumberText->SetValue(mLinkedNumberText->GetValue() + deltaValue, kRedraw); if (mNotificationRoutine != NULL) (*mNotificationRoutine)(this, deltaValue, mUserData); this->HandleEvent(fEventNumber, this, NULL); (void) this->Focus(); } void AGALittleArrowsMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGALittleArrowsMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); FailNIL(mAGAObject = new AGALittleArrows(bounds)); mAGAObject->InstallNotificationRoutine(AGALittleArrowsMA::RealAGANotifier, this); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); if (fUserArea != 0) { mLinkedNumberText = (TNumberText*) this->GetWindow()->FindSubView(fUserArea); if (mLinkedNumberText != NULL) if (! MA_MEMBER(mLinkedNumberText, TNumberText)) mLinkedNumberText = NULL; } } void AGALittleArrowsMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGALittleArrowsMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGALittleArrowsMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse; if tracking succeeds // handle our event number. if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse))) this->HandleEvent(fEventNumber, this, NULL); } void AGALittleArrowsMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGALittleArrowsMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } void AGALittleArrowsMA::RealAGANotifier(AGALittleArrows* theAGAObject, SInt32 deltaValue, void* userData) { // This is a static function. Cast the user data to get // the AGAScrollerScrollBarMA object, have it handle the notification. ((AGALittleArrowsMA*) userData)->HandleNotification(deltaValue); } // // AGADisclosureTriangleMA ---------------------------------------------------- // #undef Inherited #define Inherited TControl MA_DEFINE_CLASS_M1(AGADisclosureTriangleMA, Inherited); AGADisclosureTriangleMA::AGADisclosureTriangleMA() { mAGAObject = NULL; } AGADisclosureTriangleMA::~AGADisclosureTriangleMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGADisclosureTriangleMA::IAGADisclosureTriangleMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle) { this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle); this->CreateAGAObject(); } void AGADisclosureTriangleMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGADisclosureTriangleMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); FailNIL(mAGAObject = new AGADisclosureTriangle(bounds, AGAObject::kAutomaticState)); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGADisclosureTriangleMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGADisclosureTriangleMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGADisclosureTriangleMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Let the AGAObject track the mouse; if tracking succeeds // handle our event number. if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse))) this->HandleEvent(fEventNumber, this, NULL); } void AGADisclosureTriangleMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGADisclosureTriangleMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } // // AGAProgressIndicatorMA ---------------------------------------------------- // #undef Inherited #define Inherited TControl MA_DEFINE_CLASS_M1(AGAProgressIndicatorMA, Inherited); AGAProgressIndicatorMA::AGAProgressIndicatorMA() { mAGAObject = NULL; } AGAProgressIndicatorMA::~AGAProgressIndicatorMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGAProgressIndicatorMA::IAGAProgressIndicatorMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle) { this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle); this->CreateAGAObject(); } void AGAProgressIndicatorMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGAProgressIndicatorMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); FailNIL(mAGAObject = new AGAProgressIndicator(bounds, 0, 100)); if (! fEnabled) mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw); } void AGAProgressIndicatorMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGAProgressIndicatorMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGAProgressIndicatorMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGAProgressIndicatorMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } // // AGASeparatorMA ---------------------------------------------------- // #undef Inherited #define Inherited TView MA_DEFINE_CLASS_M1(AGASeparatorMA, Inherited); AGASeparatorMA::AGASeparatorMA() { mAGAObject = NULL; } AGASeparatorMA::~AGASeparatorMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGASeparatorMA::IAGASeparatorMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet) { this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet); this->CreateAGAObject(); } void AGASeparatorMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGASeparatorMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); FailNIL(mAGAObject = new AGASeparator(bounds)); } void AGASeparatorMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGASeparatorMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } // // AGATargetBorderViewMA ---------------------------------------------------- // #undef Inherited #define Inherited TTargetBorderView MA_DEFINE_CLASS_M1(AGATargetBorderViewMA, Inherited); void AGATargetBorderViewMA::IAGATargetBorderViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView) { this->ITargetBorderView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView); } void AGATargetBorderViewMA::Draw(const VRect& area) { // Set the color, always draw. TTargetBorderView leaves // background unerased in 1-bit. GDIterator iter; Boolean deep; Boolean isTarget = this->ContainsTarget(gApplication->GetTarget()); CTemporaryRegion borderRegion; while (iter.More(deep)) { if (deep) { if (isTarget) ::RGBForeColor(&gAGARamp[r8]); else ::RGBForeColor(&gAGARamp[r2]); } else { if (isTarget) ::RGBForeColor(&gAGARamp[rB]); else ::RGBForeColor(&gAGARamp[rW]); } this->ComputeBorderRegion(borderRegion); PaintRgn(borderRegion); } } void AGATargetBorderViewMA::ComputeBorderRegion(RgnHandle borderRegion) { // Return the border region to be painted or invalidated. CRect qdArea; CTemporaryRegion innerRegion; this->GetQDExtent(qdArea); ::OpenRgn(); ::FrameRoundRect(qdArea, 4, 4); ::CloseRgn(borderRegion); ::InsetRect(qdArea, 2, 2); ::RectRgn(innerRegion, qdArea); ::DiffRgn(borderRegion, innerRegion, borderRegion); } // // AGATargetBorderFrameViewMA ---------------------------------------------------- // #undef Inherited #define Inherited AGATargetBorderViewMA MA_DEFINE_CLASS_M1(AGATargetBorderFrameViewMA, Inherited); void AGATargetBorderFrameViewMA::IAGATargetBorderFrameViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView) { this->IAGATargetBorderViewMA(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView); } void AGATargetBorderFrameViewMA::Draw(const VRect& area) { // Let the AGATargetBorderViewMA draw the target border, // then draw the "3D" sunken frame portion.. Inherited::Draw(area); CRect qdArea; this->GetQDExtent(qdArea); ::InsetRect(qdArea, 3, 3); // // Draw the frame with shading outside. // enum { TL, Frame, BR, kNumColors }; UInt8 colorIndex[kNumColors]; GDIterator iter; Boolean deep; while (iter.More(deep)) { if (deep) { if (this->IsEnabled()) { colorIndex[TL] = r5; colorIndex[Frame] = rB; colorIndex[BR] = rW; } else { colorIndex[TL] = r4; colorIndex[Frame] = r10; colorIndex[BR] = r1; } } else // 1-bit { colorIndex[Frame] = rB; if (! this->IsEnabled()) ::PenPat(&qd.gray); } ::RGBForeColor(&gAGARamp[colorIndex[Frame]]); ::InsetRect(qdArea, 1, 1); ::FrameRect(qdArea); ::InsetRect(qdArea, -1, -1); if (deep) { ::RGBForeColor(&gAGARamp[colorIndex[TL]]); ::MoveTo(qdArea.left, qdArea.bottom - 2); ::LineTo(qdArea.left, qdArea.top); ::LineTo(qdArea.right - 2, qdArea.top); ::RGBForeColor(&gAGARamp[colorIndex[BR]]); ::MoveTo(qdArea.left + 1, qdArea.bottom - 1); ::LineTo(qdArea.right - 1, qdArea.bottom - 1); ::LineTo(qdArea.right - 1, qdArea.top + 1); } else if (! this->IsEnabled()) ::PenPat(&qd.black); } ::RGBForeColor(&gAGARamp[rB]); } void AGATargetBorderFrameViewMA::Dim(const VRect& area) { // Suppress patBic painting over our frame. } void AGATargetBorderFrameViewMA::SetEnable(Boolean state) { // Redraw now; unlike TControl, TView does not automatically // redraw when you disable/dim it. Inherited::SetEnable(state); if (this->Focus()) { VRect extent; this->GetExtent(extent); this->Draw(extent); } } // // AGAGroupBoxMA ---------------------------------------------------- // #undef Inherited #define Inherited TCluster MA_DEFINE_CLASS_M1(AGAGroupBoxMA, Inherited); AGAGroupBoxMA::AGAGroupBoxMA() { mAGAObject = NULL; } AGAGroupBoxMA::~AGAGroupBoxMA() { // Delete AGA object if we successfully allocated it. if (mAGAObject != NULL) delete mAGAObject; } void AGAGroupBoxMA::IAGAGroupBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex) { this->ICluster(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex); this->CreateAGAObject(); } void AGAGroupBoxMA::DoPostCreate(TDocument* itsDocument) { // Create and set up the AGAObject. Inherited::DoPostCreate(itsDocument); this->CreateAGAObject(); } void AGAGroupBoxMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. CStr255 label; VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); this->GetLabel(label); FailNIL(mAGAObject = new AGAGroupBox(bounds, AGATextStyle(fTextStyle), AGAGroupBox::kPrimaryGroupBox, label)); if ((fUserArea != 0) && (fSuperView != NULL)) { TView* gapView = fSuperView->FindSubView(fUserArea); if (gapView != NULL) { CRect gapExtent; gapView->GetQDExtent(gapExtent); mAGAObject->SetTitleGap(5 + gapExtent.GetLength(hSel)); } } } void AGAGroupBoxMA::Draw(const VRect& area) { // Let the AGAObject draw itself. if (mAGAObject != NULL) mAGAObject->DrawObject(); } void AGAGroupBoxMA::SetFrame(const VRect& newFrame, Boolean invalidate) { // Let the MacApp and AGA objects update their locations. Inherited::SetFrame(newFrame, invalidate); SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate); } void AGAGroupBoxMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis) { // Group box drawing is based on enable state, but we don't // want clicking on the group box itself to cause highlighting. } void AGAGroupBoxMA::DimState(Boolean state, Boolean redraw) { // Set the AGAObject's enable state. if (mAGAObject != NULL) { Boolean wantRedraw = redraw && this->Focus(); mAGAObject->SetEnable(!state, wantRedraw); } } void AGAGroupBoxMA::Dim() { // Set the AGAObject's enable state, with immediate redraw. if (mAGAObject != NULL) mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus()); } // // AGASecondaryGroupBoxMA ---------------------------------------------------- // #undef Inherited #define Inherited AGAGroupBoxMA MA_DEFINE_CLASS_M1(AGASecondaryGroupBoxMA, Inherited); void AGASecondaryGroupBoxMA::IAGASecondaryGroupBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex) { this->IAGAGroupBoxMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex); } void AGASecondaryGroupBoxMA::CreateAGAObject() { // Instantiate the particular AGAObject subclass. CStr255 label; VRect viewRect(0, 0, fSize.h, fSize.v); CRect bounds; this->ViewToQDRect(viewRect, bounds); this->GetLabel(label); FailNIL(mAGAObject = new AGAGroupBox(bounds, AGATextStyle(fTextStyle), AGAGroupBox::kSecondaryGroupBox, label)); }